package com.itheima.tlias84.controller;

import com.itheima.tlias84.config.OssClient;
import com.itheima.tlias84.utils.ResultUtil;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@Slf4j
@RestController
@RequestMapping("/upload")
public class UploadController {

    @Resource
    OssClient ossClient;

    /**
     * MultipartFile spring封装的用来接受文件的对象
     *
     * @param file
     * @return
     */
    @PostMapping
    public ResultUtil upload(MultipartFile file) throws IOException {

        String url = ossClient.upload(file.getOriginalFilename(), file.getInputStream());

        return ResultUtil.success(url, true);
    }
}
